<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">












  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.2.0" color="#222">






<link rel="stylesheet" href="/css/main.css?v=7.2.0">






<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">






  
  
  <link rel="stylesheet" href="/lib/fancybox/source/jquery.fancybox.css">



<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    copycode: {"enable":true,"show_result":true,"style":null},
    fancybox: true,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    search: {
      root: '/',
      path: 'search.xml'
    },
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="Flutter - 鹰眼视频鹰眼视频 App 相关技术知识点    目录结构 页面拆封 封装 dio &amp;lt; Flutter http 插件 &amp;gt; 使用懒加载图片特效 json自动序列化 model 映射 ListView 组件 GestureDetector 手势 路由导航 视频播放  目录结构 1234567lib    comments    // 组件封装    model">
<meta name="keywords" content="flutter">
<meta property="og:type" content="article">
<meta property="og:title" content="鹰眼视频 (一)">
<meta property="og:url" content="https://blog.youngzk.com/posts/ab4a2db7/index.html">
<meta property="og:site_name" content="Muniz Blog">
<meta property="og:description" content="Flutter - 鹰眼视频鹰眼视频 App 相关技术知识点    目录结构 页面拆封 封装 dio &amp;lt; Flutter http 插件 &amp;gt; 使用懒加载图片特效 json自动序列化 model 映射 ListView 组件 GestureDetector 手势 路由导航 视频播放  目录结构 1234567lib    comments    // 组件封装    model">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://blog.youngzk.com/posts/ab4a2db7/yyspflutterhome.png">
<meta property="og:updated_time" content="2019-07-28T05:22:54.722Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="鹰眼视频 (一)">
<meta name="twitter:description" content="Flutter - 鹰眼视频鹰眼视频 App 相关技术知识点    目录结构 页面拆封 封装 dio &amp;lt; Flutter http 插件 &amp;gt; 使用懒加载图片特效 json自动序列化 model 映射 ListView 组件 GestureDetector 手势 路由导航 视频播放  目录结构 1234567lib    comments    // 组件封装    model">
<meta name="twitter:image" content="https://blog.youngzk.com/posts/ab4a2db7/yyspflutterhome.png">





  
  
  <link rel="canonical" href="https://blog.youngzk.com/posts/ab4a2db7/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  
  <title>鹰眼视频 (一) | Muniz Blog</title>
  






  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?502753d7b083822cd84ffc61132a5ac4";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>







  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Muniz Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-books">

    
    
      
    

    

    <a href="/books" rel="section"><i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>阅读</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          <a href="javascript:;" class="popup-trigger">
          
            <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.youngzk.com/posts/ab4a2db7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="修心">
      <meta itemprop="description" content="修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Muniz Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">鹰眼视频 (一)

              
            
          </h1>
        

        <div class="post-meta">

          
          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-11-04 20:00:30" itemprop="dateCreated datePublished" datetime="2018-11-04T20:00:30+08:00">2018-11-04</time>
            </span>
          

          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-07-28 13:22:54" itemprop="dateModified" datetime="2019-07-28T13:22:54+08:00">2019-07-28</time>
              </span>
            
          

          

          
          

          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
                 阅读次数： 
                <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
              </span>
            </span>
          

          

          <br>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Flutter-鹰眼视频"><a href="#Flutter-鹰眼视频" class="headerlink" title="Flutter - 鹰眼视频"></a>Flutter - 鹰眼视频</h2><p>鹰眼视频 App 相关技术知识点</p>
<img src="/posts/ab4a2db7/yyspflutterhome.png" title="鹰眼视频">

<ul>
<li>目录结构</li>
<li>页面拆封</li>
<li>封装 dio &lt; Flutter http 插件 &gt;</li>
<li>使用懒加载图片特效</li>
<li>json自动序列化 model 映射</li>
<li>ListView 组件</li>
<li>GestureDetector 手势</li>
<li>路由导航</li>
<li>视频播放</li>
</ul>
<h3 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h3> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">lib</span><br><span class="line">    comments    // 组件封装</span><br><span class="line">    model       // 序列号model</span><br><span class="line">    page        // 页面</span><br><span class="line">    serves      // http 相关的 目录 </span><br><span class="line">    view        // 存放一些 组件组合的 控件</span><br><span class="line">    main.dart   // Flutter入口dart文件</span><br></pre></td></tr></table></figure>

 <a id="more"></a>

<h3 id="页面拆封"><a href="#页面拆封" class="headerlink" title="页面拆封"></a>页面拆封</h3><h4 id="main-dart-入口文件内容"><a href="#main-dart-入口文件内容" class="headerlink" title="main.dart 入口文件内容"></a>main.dart 入口文件内容</h4> <figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/page/homePage.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Flutter 入口main函数</span></span><br><span class="line"><span class="keyword">void</span> main()=&gt;runApp(<span class="keyword">new</span> RootPage());</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RootPage</span> <span class="keyword">extends</span> <span class="title">StatelessWidget</span> </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> MaterialApp(</span><br><span class="line">      title: <span class="string">'鹰眼视频'</span>,</span><br><span class="line">      home: <span class="keyword">new</span> HomePage()</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>RootPage组件类是根入口,用于汇集所有的 page页面。同时页面的路由配置就可以放到这个RootPage类中去管理。</p>
<p>导入其他文件时的2中方法，如下。</p>
<blockquote>
<p>import ‘package:yysp/page/homePage.dart’;<br>import ‘./page/homePage.dart’;</p>
</blockquote>
<h4 id="homePage-dart-首页"><a href="#homePage-dart-首页" class="headerlink" title="homePage.dart 首页"></a>homePage.dart 首页</h4><p>该文件存放在 ** /page/ ** 目录下, ** page ** 目录用于管理所有的页面资源。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">HomePage</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  _HomePageState createState() =&gt; _HomePageState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_HomePageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">HomePage</span>&gt; </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    Widget build(BuildContext context) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> MaterialApp(</span><br><span class="line">            home: <span class="keyword">new</span> Scaffold(</span><br><span class="line">                appBar: AppBar(</span><br><span class="line">                    title: Text(</span><br><span class="line">                        <span class="string">"鹰眼视频"</span>,</span><br><span class="line">                        style: <span class="keyword">new</span> TextStyle(fontSize: <span class="number">20.0</span>, letterSpacing: <span class="number">3.0</span>),</span><br><span class="line">                    ),</span><br><span class="line">                ),</span><br><span class="line">                body: <span class="keyword">new</span> Text(<span class="string">'我是首页'</span>),</span><br><span class="line">            ),</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    <span class="keyword">void</span> initState() &#123;</span><br><span class="line">        <span class="keyword">super</span>.initState();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这是一个最基本的有状态组件,有状态组件可以做交互、让组件可控。如react中的 this.setState()后，组件就会重新绘制。不过Flutter中的修改状态值的方法是 ** setState((){ }) ** ,与React 一样。</p>
<h3 id="封装自己的dio"><a href="#封装自己的dio" class="headerlink" title="封装自己的dio"></a>封装自己的dio</h3><p>Api.dart、httpUtil.dart 文件都存放在 ** /servers/**目录下。</p>
<p>Api.dart 文件内容</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Api</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 基础 Url</span></span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">const</span> <span class="built_in">String</span> BaseUrl = <span class="string">'https://436086407.dmi.net.cn/weapp/'</span>;</span><br><span class="line">    <span class="comment">// 视频列表</span></span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">const</span> <span class="built_in">String</span> VideList = <span class="string">'<span class="subst">$BaseUrl</span>/videolist'</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>httpUtil.dart 文件内容</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:dio/dio.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/servers/Api.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">HttpUtil</span> </span>&#123;</span><br><span class="line">  <span class="keyword">static</span> HttpUtil instance;</span><br><span class="line">  Dio dio;</span><br><span class="line">  Options options;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">static</span> HttpUtil getInstance() &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">'getInstance'</span>);</span><br><span class="line">    <span class="keyword">if</span> (instance == <span class="keyword">null</span>) &#123;</span><br><span class="line">      instance = <span class="keyword">new</span> HttpUtil();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> instance;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  HttpUtil() &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">'dio赋值'</span>);</span><br><span class="line">    options = Options(</span><br><span class="line">      baseUrl: Api.BaseUrl,</span><br><span class="line">      connectTimeout: <span class="number">10000</span>,</span><br><span class="line">      receiveTimeout: <span class="number">3000</span>,</span><br><span class="line">      headers: &#123;&#125;,</span><br><span class="line">    );</span><br><span class="line">    dio = <span class="keyword">new</span> Dio(options);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">get</span>(url, &#123;data, options, cancelToken&#125;) <span class="keyword">async</span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">'get请求启动! url：<span class="subst">$url</span> ,body: <span class="subst">$data</span>'</span>);</span><br><span class="line">    Response response;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">      response = <span class="keyword">await</span> dio.<span class="keyword">get</span>(</span><br><span class="line">        url,</span><br><span class="line">        data: data,</span><br><span class="line">        cancelToken: cancelToken,</span><br><span class="line">      );</span><br><span class="line">      <span class="built_in">print</span>(<span class="string">'get请求成功!response.data：<span class="subst">$&#123;response.data&#125;</span>'</span>);</span><br><span class="line">    &#125; on DioError <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">      <span class="keyword">if</span> (CancelToken.isCancel(e)) &#123;</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">'get请求取消! '</span> + e.message);</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="built_in">print</span>(<span class="string">'get请求发生错误：<span class="subst">$e</span>'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> response.data;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  post(url, &#123;data, options, cancelToken&#125;) <span class="keyword">async</span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">'post请求启动! url：<span class="subst">$url</span> ,body: <span class="subst">$data</span>'</span>);</span><br><span class="line">    Response response;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">      response = <span class="keyword">await</span> dio.post(</span><br><span class="line">        url,</span><br><span class="line">        data: data,</span><br><span class="line">        cancelToken: cancelToken,</span><br><span class="line">      );</span><br><span class="line">      <span class="built_in">print</span>(<span class="string">'post请求成功!response.data：<span class="subst">$&#123;response.data&#125;</span>'</span>);</span><br><span class="line">    &#125; on DioError <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">      <span class="keyword">if</span> (CancelToken.isCancel(e)) &#123;</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">'post请求取消! '</span> + e.message);</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="built_in">print</span>(<span class="string">'post请求发生错误：<span class="subst">$e</span>'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> response.data;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这里httpUtil类，采用了单列模式。可以想一下 ** java ** 中连接数据库JDBC的情景。</p>
<h3 id="使用懒加载图片特效"><a href="#使用懒加载图片特效" class="headerlink" title="使用懒加载图片特效"></a>使用懒加载图片特效</h3><p>实现这个效果，需要使用第三方的插件。 在 ** pubspec.yaml ** 中添加。</p>
<p>Flutter与node 使用第三方库的区别。</p>
<ul>
<li>node 可以 npm i xxx ,也可以在package 中直接写库名，然后执行 npm i。</li>
<li>flutter 需要手动写到 pubspec.yaml中，在执行 flutter packages get 。</li>
</ul>
<p>加载图片特效插件：transparent_image</p>
<p>封装图片组件，代码示意图</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 图片懒惰加载</span></span><br><span class="line">Widget _buildImage(<span class="built_in">String</span> imgUrl) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> FadeInImage.memoryNetwork(</span><br><span class="line">        placeholder: kTransparentImage,</span><br><span class="line">        image: imgUrl,</span><br><span class="line">        height: <span class="number">200.0</span>,</span><br><span class="line">        fit: BoxFit.fitWidth,</span><br><span class="line">        fadeInDuration: <span class="keyword">const</span> <span class="built_in">Duration</span>(milliseconds: <span class="number">300</span>),</span><br><span class="line">        fadeOutDuration: <span class="keyword">const</span> <span class="built_in">Duration</span>(milliseconds: <span class="number">300</span>),</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="json自动序列化-model-映射"><a href="#json自动序列化-model-映射" class="headerlink" title="json自动序列化 model 映射"></a>json自动序列化 model 映射</h3><p>我们在向服务器请求数据后，服务器往往会返回一段json字符串。而我们要想更加灵活的使用数据的话需要把json字符串转化成对象。由于flutter只提供了json to Map。而手写反序列化在大型项目中极不稳定，很容易导致解析失败。所以flutter团队推荐使用json_serializable 自动反序列化。</p>
<p>使用第三方库： json_annotation: ^2.0.0 \ build_runner \ json_serializable</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">dependencies:</span><br><span class="line">  flutter:</span><br><span class="line">    sdk: flutter</span><br><span class="line">  json_annotation: ^<span class="number">2.0</span><span class="number">.0</span></span><br><span class="line"></span><br><span class="line">dev_dependencies:</span><br><span class="line">  flutter_test:</span><br><span class="line">    sdk: flutter</span><br><span class="line">  build_runner: ^<span class="number">1.1</span><span class="number">.0</span></span><br><span class="line">  json_serializable: ^<span class="number">2.0</span><span class="number">.0</span></span><br></pre></td></tr></table></figure>

<h4 id="flutter中如何解析json对象"><a href="#flutter中如何解析json对象" class="headerlink" title="flutter中如何解析json对象"></a>flutter中如何解析json对象</h4><p>假如我们的mock数据是如下形式。</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">"id"</span> : <span class="number">8863</span>,</span><br><span class="line">    <span class="attr">"list"</span> : [ <span class="number">8952</span>, <span class="number">9224</span>, <span class="number">8917</span> ],</span><br><span class="line">    <span class="attr">"score"</span> : <span class="number">111</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>那么我们需要根据相应的json数据去创建对应的model实体类</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:json_annotation/json_annotation.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Data</span></span>&#123;</span><br><span class="line">  <span class="keyword">final</span> <span class="built_in">int</span> id;</span><br><span class="line">  <span class="meta">@JsonKey</span>(name: <span class="string">'list'</span>)</span><br><span class="line">  <span class="keyword">final</span> <span class="built_in">List</span>&lt;<span class="built_in">int</span>&gt; listData;</span><br><span class="line">  <span class="keyword">final</span> <span class="built_in">int</span> score;</span><br><span class="line"></span><br><span class="line">  Data(&#123;<span class="keyword">this</span>.id, <span class="keyword">this</span>.listData, <span class="keyword">this</span>.score&#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在这里使用了 ** @JsonKey(name: ‘list) ** ,原因是，因为我们的json数据中使用了list关键字,所以我们给起个别名listData。并且与Json的list字断映射！</p>
<h4 id="生成Json解析文件"><a href="#生成Json解析文件" class="headerlink" title="生成Json解析文件"></a>生成Json解析文件</h4><p>在这里，我们需要使用 ** build_runner ** 去生成dart代码，** build_runner **是dart团队提供的一个生成dart代码文件的外部包。</p>
<p>当前项目的目录下运行</p>
<blockquote>
<p>flutter packages pub run build_runner build</p>
</blockquote>
<p>运行成功后，就可以在我们的model实体类下面看见一个叫 ** Data.g.dart ** 的文件，内容如下：</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// GENERATED CODE - DO NOT MODIFY BY HAND</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">part</span> of <span class="string">'data.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// **************************************************************************</span></span><br><span class="line"><span class="comment">// JsonSerializableGenerator</span></span><br><span class="line"><span class="comment">// **************************************************************************</span></span><br><span class="line"></span><br><span class="line">Data _$DataFromJson(<span class="built_in">Map</span>&lt;<span class="built_in">String</span>, <span class="keyword">dynamic</span>&gt; json) &#123;</span><br><span class="line">  <span class="keyword">return</span> Data(</span><br><span class="line">      id: json[<span class="string">'id'</span>] <span class="keyword">as</span> <span class="built_in">int</span>,</span><br><span class="line">      kids: (json[<span class="string">'kids'</span>] <span class="keyword">as</span> <span class="built_in">List</span>)?.map((e) =&gt; e <span class="keyword">as</span> <span class="built_in">int</span>)?.toList(),</span><br><span class="line">      score: json[<span class="string">'score'</span>] <span class="keyword">as</span> <span class="built_in">int</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">Map</span>&lt;<span class="built_in">String</span>, <span class="keyword">dynamic</span>&gt; _$DataToJson(Data instance) =&gt; &lt;<span class="built_in">String</span>, <span class="keyword">dynamic</span>&gt;&#123;</span><br><span class="line">      <span class="string">'id'</span>: instance.id,</span><br><span class="line">      <span class="string">'kids'</span>: instance.kids,</span><br><span class="line">      <span class="string">'score'</span>: instance.score</span><br><span class="line">    &#125;;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注释 ** GENERATED CODE - DO NOT MODIFY BY HAND” **, 意思是不要手写生成这个文件，使用根据去解决。</p>
</blockquote>
<h4 id="关联实体类文件"><a href="#关联实体类文件" class="headerlink" title="关联实体类文件"></a>关联实体类文件</h4><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:json_annotation/json_annotation.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">part</span> <span class="string">'data.g.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">@JsonSerializable</span>()</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Data</span></span>&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">int</span> id;</span><br><span class="line">    <span class="meta">@JsonKey</span>(name: <span class="string">'list'</span>)</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">List</span>&lt;<span class="built_in">int</span>&gt; listData;</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">int</span> score;</span><br><span class="line"></span><br><span class="line">    Data(&#123;<span class="keyword">this</span>.id, <span class="keyword">this</span>.listData, <span class="keyword">this</span>.score&#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//反序列化</span></span><br><span class="line">    <span class="keyword">factory</span> Data.fromJson(<span class="built_in">Map</span>&lt;<span class="built_in">String</span>, <span class="keyword">dynamic</span>&gt; json) =&gt; _$DataFromJson(json);</span><br><span class="line">    <span class="comment">//序列化</span></span><br><span class="line">    <span class="built_in">Map</span>&lt;<span class="built_in">String</span>, <span class="keyword">dynamic</span>&gt; toJson() =&gt; _$DataToJson(<span class="keyword">this</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="ListView-组件"><a href="#ListView-组件" class="headerlink" title="ListView 组件"></a>ListView 组件</h3><p>在Flutter中,用ListView来显示列表项,支持垂直和水平方向展示,通过一个属性我们就可以控制其方向，在这里只做大数据的渲染介绍。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/servers/httpUtil.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/servers/Api.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/model/videos.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">HomePage</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">  <span class="meta">@override</span></span><br><span class="line">  _HomePageState createState() =&gt; _HomePageState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_HomePageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">HomePage</span>&gt; </span>&#123;</span><br><span class="line">    HttpUtil httpUtil = <span class="keyword">new</span> HttpUtil();</span><br><span class="line">    <span class="built_in">List</span>&lt;<span class="keyword">dynamic</span>&gt; _videosList = <span class="keyword">new</span> <span class="built_in">List</span>(); <span class="comment">// 视频列表数据</span></span><br><span class="line">    <span class="built_in">int</span> _pageNo = <span class="number">0</span>; <span class="comment">// 开始页</span></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    Widget build(BuildContext context) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> MaterialApp(</span><br><span class="line">            home: <span class="keyword">new</span> Scaffold(</span><br><span class="line">                appBar: AppBar(</span><br><span class="line">                    title: Text(</span><br><span class="line">                        <span class="string">"鹰眼视频"</span>,</span><br><span class="line">                        style: <span class="keyword">new</span> TextStyle(fontSize: <span class="number">20.0</span>, letterSpacing: <span class="number">3.0</span>),</span><br><span class="line">                    ),</span><br><span class="line">                ),</span><br><span class="line">                <span class="comment">// 这是listView 实现 大数据渲染的 方法</span></span><br><span class="line">                body: <span class="keyword">new</span> ListView.builder(</span><br><span class="line">                    itemCount: _videosList.length,</span><br><span class="line">                    itemBuilder: <span class="keyword">this</span>._buildRow,</span><br><span class="line">                ),</span><br><span class="line">            ),</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    <span class="keyword">void</span> initState() &#123;</span><br><span class="line">        <span class="keyword">super</span>.initState();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// listView 子项 itemBuilder build方法 传入2个参数，( context 上下文, position 下标 - 计数器)</span></span><br><span class="line">    Widget _buildRow(BuildContext context, <span class="built_in">int</span> position) &#123;</span><br><span class="line">        <span class="built_in">print</span>(_videosList[position].toString());</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Card(</span><br><span class="line">            margin: EdgeInsets.only(bottom: <span class="number">38.0</span>),</span><br><span class="line">            child: <span class="keyword">new</span> Container(</span><br><span class="line">                height: <span class="number">256.0</span>,</span><br><span class="line">                child: <span class="keyword">this</span>._buildImage(_videosList[position][<span class="string">'img'</span>])</span><br><span class="line">            )</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    <span class="keyword">void</span> initState() &#123;</span><br><span class="line">        <span class="keyword">super</span>.initState();</span><br><span class="line">        _getContent(_pageNo);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//获取网络数据</span></span><br><span class="line">    <span class="keyword">void</span> _getContent(pageNo) <span class="keyword">async</span> &#123;</span><br><span class="line">        <span class="built_in">String</span> url = Api.VideList;</span><br><span class="line">        <span class="keyword">var</span> data = &#123;<span class="string">'page'</span>: pageNo&#125;;</span><br><span class="line">        <span class="keyword">var</span> response = <span class="keyword">await</span> HttpUtil().<span class="keyword">get</span>(url, data: data);</span><br><span class="line">        Videos videos = Videos.fromJson(response);</span><br><span class="line">        <span class="keyword">if</span> (videos.code == <span class="number">0</span>) &#123;</span><br><span class="line">            setState(() &#123;</span><br><span class="line">                _videosList.addAll(videos.data.listData);</span><br><span class="line">                _pageNo = pageNo + <span class="number">1</span>;</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上面介绍了 如何http 获取数据，并且把json数据映射到model实体类。其实listView最主要的就是，做大数据渲染。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//ListView 核心</span></span><br><span class="line"><span class="keyword">new</span> ListView.builder(</span><br><span class="line">    itemCount: _videosList.length,</span><br><span class="line">    itemBuilder: <span class="keyword">this</span>._buildRow,</span><br><span class="line">),</span><br><span class="line"></span><br><span class="line">itemCount: 表示列表项的总数。</span><br><span class="line">itemBuilder： 渲染子项的方法，使其list列表中显示不同的组件界面。</span><br></pre></td></tr></table></figure>

<h3 id="GestureDetector-手势"><a href="#GestureDetector-手势" class="headerlink" title="GestureDetector 手势"></a>GestureDetector 手势</h3><p>GestureDetector 手势控件没有图像展示，只是检测用户输入的手势。当用户点击Container时，GestureDetector会调用onTap回调。也可以使用GestureDetector检测各种输入手势，包括点击、拖动和缩放。不过也有许多的控件使用GestureDetector为其他控件提供回调，比如IconButton、RaisedButton和FloatingActionButton控件有onPressed回调，当用户点击控件时触发回调。</p>
<h4 id="手势事件"><a href="#手势事件" class="headerlink" title="手势事件"></a>手势事件</h4><table>
<thead>
<tr>
<th>属性/回调</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>onTapDown</td>
<td>每次用户与屏幕联系时都会触发 OnTapDown</td>
</tr>
<tr>
<td>onTapUp</td>
<td>当用户停止触摸屏幕时，onTapUp 被调用</td>
</tr>
<tr>
<td>onTap</td>
<td>当短暂触摸屏幕时，onTap 被触发</td>
</tr>
<tr>
<td>onTapCancel</td>
<td>当用户触摸屏幕但未完成 Tap 时，将触发此事件</td>
</tr>
<tr>
<td>onDoubleTap</td>
<td>当屏幕被快速连续触摸两次时调用 onDoubleTap</td>
</tr>
<tr>
<td>onLongPress</td>
<td>用户触摸屏幕超过 500毫秒 时，onLongPress 被触发</td>
</tr>
<tr>
<td>onVerticalDragDown</td>
<td>当指针与屏幕接触并开始沿垂直方向移动时，onVerticalDown 被调用</td>
</tr>
<tr>
<td>onVerticalDragStart</td>
<td>当指针 开始 沿垂直方向移动时调用 onVerticalDragStart</td>
</tr>
<tr>
<td>onVerticalDragUpdate</td>
<td>每次指针在屏幕上的位置发生变化时都会调用此方法</td>
</tr>
<tr>
<td>onVerticalDragEnd</td>
<td>当用户停止移动时，拖动被认为是完成的，将调用此事件</td>
</tr>
<tr>
<td>onVerticalDragCancel</td>
<td>当用户突然停止拖动时调用</td>
</tr>
<tr>
<td>onHorizontalDragDown</td>
<td>当用户/指针与屏幕接触并开始水平移动时调用</td>
</tr>
<tr>
<td>onHorizontalDragStart</td>
<td>用户/指针已与屏幕接触并 开始 沿水平方向移动</td>
</tr>
<tr>
<td>onHorizontalDragUpdate</td>
<td>每次指针在水平方向/x轴上的位置发生变化时调用</td>
</tr>
<tr>
<td>onHorizontalDragEnd</td>
<td>在水平拖动结束时，将调用此事件</td>
</tr>
<tr>
<td>onHorizontalDragCancel</td>
<td>当指针未成功触发 onHorizontalDragDown 时调用</td>
</tr>
<tr>
<td>onPanDown</td>
<td>当指针与屏幕接触时调用</td>
</tr>
<tr>
<td>onPanStart</td>
<td>指针事件开始移动时，onPanStart 触发</td>
</tr>
<tr>
<td>onPanUpdate</td>
<td>每次指针改变位置时，调用 onPanUpdate</td>
</tr>
<tr>
<td>onPanEnd</td>
<td>平移完成后，将调用此事件</td>
</tr>
<tr>
<td>onScaleStart</td>
<td>当指针与屏幕接触并建立 1.0 的焦点时，将调用此事件</td>
</tr>
<tr>
<td>onScaleUpdate</td>
<td>与屏幕接触的指针指示了新的焦点</td>
</tr>
<tr>
<td>onScaleEnd</td>
<td>当指针不再与指示手势结束的屏幕接触时调用</td>
</tr>
</tbody></table>
<h4 id="onTap-事咧"><a href="#onTap-事咧" class="headerlink" title="onTap 事咧"></a>onTap 事咧</h4><p>这里以onTap手势事件，为例。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 传参数的手势。</span></span><br><span class="line"><span class="keyword">new</span> GestureDetector(</span><br><span class="line">    child:Container(</span><br><span class="line">        width: <span class="built_in">double</span>.infinity,</span><br><span class="line">        height: <span class="number">200.0</span>,</span><br><span class="line">        child: <span class="keyword">this</span>._buildImage(_videosList[position][<span class="string">'img'</span>]), <span class="comment">// 返回的是自定义的图片组件</span></span><br><span class="line">    ),</span><br><span class="line">    onTap: <span class="keyword">this</span>._videoPlayToggle(_videosList[position][<span class="string">'id'</span>]), <span class="comment">// 这里是点击图片触发的事件，并且传入一个参数</span></span><br><span class="line">),</span><br><span class="line"></span><br><span class="line"><span class="built_in">Function</span> _videoPlayToggle(id) &#123;</span><br><span class="line">    <span class="keyword">return</span> () =&gt; parint(<span class="string">'我是onTab事件，参数 <span class="subst">$id</span>'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 不传参数的手势。</span></span><br><span class="line"><span class="keyword">new</span> GestureDetector(</span><br><span class="line">    child:Container(</span><br><span class="line">        width: <span class="built_in">double</span>.infinity,</span><br><span class="line">        height: <span class="number">200.0</span>,</span><br><span class="line">        child: Text(<span class="string">'无参数'</span>), <span class="comment">// 返回的是自定义的图片组件</span></span><br><span class="line">    ),</span><br><span class="line">    onTap: <span class="keyword">this</span>._videoPlayToggle(), <span class="comment">// 这里是点击图片触发的事件，并且传入一个参数</span></span><br><span class="line">),</span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> _videoPlayToggle() &#123;</span><br><span class="line">    parint(<span class="string">'我是onTab事件，无参数'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="路由导航"><a href="#路由导航" class="headerlink" title="路由导航"></a>路由导航</h3><p>在上节手势介绍文章中介绍了onTab事件，那么现在我们就看看app应用的多页面切换吧。看看Flutter的页面切换与 ** React-router ** 有什么不一样。</p>
<p>在Flutter中有着两种路由跳转的方式，一种是静态路由，在创建时就已经明确知道了要跳转的页面和值。另一种是动态路由，跳转传入的目标地址和要传入的值都可以是动态的。</p>
<h4 id="静态路由"><a href="#静态路由" class="headerlink" title="静态路由"></a>静态路由</h4><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/page/homePage.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/page/aboutPage.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> main()=&gt;runApp(<span class="keyword">new</span> RootPage());</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RootPage</span> <span class="keyword">extends</span> <span class="title">StatelessWidget</span> </span>&#123;</span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    Widget build(BuildContext context) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> MaterialApp(</span><br><span class="line">            title: <span class="string">'鹰眼视频'</span>,</span><br><span class="line">            home: <span class="keyword">new</span> HomePage(),</span><br><span class="line">            routes: &lt;<span class="built_in">String</span>, WidgetBuilder&gt;&#123;</span><br><span class="line">                <span class="string">'/aboutPage'</span>: (BuildContext context) =&gt; <span class="keyword">new</span> AboutPage() <span class="comment">// 静态路由配置</span></span><br><span class="line">            &#125;</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在MaterialApp中，是存在一个叫routers的参数的，用于配置静态路由。</p>
<h4 id="动态路由"><a href="#动态路由" class="headerlink" title="动态路由"></a>动态路由</h4><p>在手势的小节中讲解了，如何去使用手势事件。那么这节继续扩充。点击事件后，让其携带参数切换页面。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Function</span> _videoPlayToggle(id) &#123; <span class="comment">// 这里接收的是，事件传递的参数。</span></span><br><span class="line">    <span class="keyword">return</span> () =&gt; Navigator.of(context).push(</span><br><span class="line">        <span class="keyword">new</span> PageRouteBuilder(</span><br><span class="line">            pageBuilder: (BuildContext context,</span><br><span class="line">                Animation&lt;<span class="built_in">double</span>&gt; animation, <span class="comment">// 切换的动画。</span></span><br><span class="line">                Animation&lt;<span class="built_in">double</span>&gt; secondaryAnimation) &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">new</span> DetailsPage(id.toString()); <span class="comment">// 这里负责把事件参数，传递到下一个页面。</span></span><br><span class="line">            &#125;</span><br><span class="line">        )</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<p>原则就是：“简单的学习，快速的掌握”。至于动画效果，后续优化。先跑下框架结构！</p>
<blockquote>
<p>下一个页面的，参数接收。</p>
</blockquote>
<p>其实就是，通过构造方法实例话对象时传进去。就是这么简单。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">DetailsPage</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">String</span> videoId; <span class="comment">// 路由携带的 播放id 参数</span></span><br><span class="line"></span><br><span class="line">    DetailsPage(<span class="keyword">this</span>.videoId); <span class="comment">// 构造方法</span></span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    _DetailsPageState createState() =&gt; _DetailsPageState(<span class="keyword">this</span>.videoId); <span class="comment">// 把 参数再次向下传入。</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_DetailsPageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">DetailsPage</span>&gt; </span>&#123;</span><br><span class="line">  <span class="keyword">final</span> <span class="built_in">String</span> _videoId; <span class="comment">// 这里就是 传入的参数，这样就使用视频ID，在相应的生命周期中去获取数据了。</span></span><br><span class="line">  _DetailsPageState(<span class="keyword">this</span>._videoId); <span class="comment">// 构造方法</span></span><br></pre></td></tr></table></figure>

<p>记住，类对象必须构造方法传参数。</p>
<h3 id="视频播放"><a href="#视频播放" class="headerlink" title="视频播放"></a>视频播放</h3><p>视频播放使用了这2个插件，video_player、chewie</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:video_player/video_player.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:chewie/chewie.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/servers/httpUtil.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/servers/Api.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:yysp/model/video_detail.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">DetailsPage</span> <span class="keyword">extends</span> <span class="title">StatefulWidget</span> </span>&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">String</span> videoId; <span class="comment">// 路由携带的 播放id 参数</span></span><br><span class="line"></span><br><span class="line">    DetailsPage(<span class="keyword">this</span>.videoId);</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    _DetailsPageState createState() =&gt; _DetailsPageState(<span class="keyword">this</span>.videoId);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">_DetailsPageState</span> <span class="keyword">extends</span> <span class="title">State</span>&lt;<span class="title">DetailsPage</span>&gt; </span>&#123;</span><br><span class="line">    <span class="keyword">final</span> <span class="built_in">String</span> _videoId;</span><br><span class="line">    Video _videoInfo = <span class="keyword">new</span> Video(<span class="number">0</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="string">''</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="string">''</span>);</span><br><span class="line">    <span class="comment">// 实例化播放控制器，通过这个控制器去实现播放、暂停、视频切换。</span></span><br><span class="line">    VideoPlayerController _videoPlayController = <span class="keyword">new</span> VideoPlayerController.network(<span class="string">''</span>);</span><br><span class="line">    HttpUtil httpUtil = <span class="keyword">new</span> HttpUtil();</span><br><span class="line">    _DetailsPageState(<span class="keyword">this</span>._videoId);</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    Widget build(BuildContext context) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> MaterialApp(</span><br><span class="line">            home: <span class="keyword">new</span> Scaffold(</span><br><span class="line">                appBar: AppBar(</span><br><span class="line">                    title: Text(</span><br><span class="line">                        <span class="string">"鹰眼视频"</span>,</span><br><span class="line">                        style: <span class="keyword">new</span> TextStyle(fontSize: <span class="number">20.0</span>, letterSpacing: <span class="number">3.0</span>),</span><br><span class="line">                    ),</span><br><span class="line">                    ),</span><br><span class="line">                    body: Column(</span><br><span class="line">                    children: &lt;Widget&gt;[</span><br><span class="line">                        Container(</span><br><span class="line">                        child: <span class="keyword">this</span>._buildVideo()</span><br><span class="line">                        ),</span><br><span class="line">                        Text(_videoInfo.title)</span><br><span class="line">                    ],</span><br><span class="line">                )</span><br><span class="line">            )</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">  </span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    <span class="keyword">void</span> initState() &#123;</span><br><span class="line">        <span class="keyword">super</span>.initState();</span><br><span class="line">        <span class="keyword">this</span>._getVideoInfo();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@override</span></span><br><span class="line">    <span class="keyword">void</span> dispose() &#123;</span><br><span class="line">        <span class="keyword">super</span>.dispose();</span><br><span class="line">        _videoPlayController.pause();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//获取网络数据 视频播放详情</span></span><br><span class="line">    <span class="keyword">void</span> _getVideoInfo() <span class="keyword">async</span> &#123;</span><br><span class="line">        <span class="built_in">String</span> url = Api.VideoInfo;</span><br><span class="line">        <span class="keyword">var</span> data = &#123;<span class="string">'id'</span>: <span class="keyword">this</span>._videoId&#125;;</span><br><span class="line">        <span class="keyword">var</span> response = <span class="keyword">await</span> HttpUtil().<span class="keyword">get</span>(url, data: data);</span><br><span class="line">        VideoDetail videos = VideoDetail.fromJson(response);</span><br><span class="line">        <span class="keyword">if</span> (videos.code == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="comment">// 视频获取回来，就初始化 播放控制器</span></span><br><span class="line">        _videoPlayController = VideoPlayerController.network( videos.data.video.src );</span><br><span class="line">        setState(() &#123;</span><br><span class="line">            _videoInfo = <span class="keyword">new</span> Video(videos.data.video.id, videos.data.video.title, videos.data.video.url, videos.data.video.auther, videos.data.video.pubtime, videos.data.video.img, videos.data.video.src, videos.data.video.desc1, videos.data.video.cate, videos.data.video.pt, videos.data.video.collect, videos.data.video.count, videos.data.video.insertTime);</span><br><span class="line">        &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 视频 组件，传递了VideoPlayController控制器</span></span><br><span class="line">    Widget _buildVideo() &#123;</span><br><span class="line">        _videoPlayController.play();</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Chewie(</span><br><span class="line">            _videoPlayController,</span><br><span class="line">            aspectRatio: <span class="number">3</span> / <span class="number">2</span>,</span><br><span class="line">            autoPlay: <span class="keyword">true</span>,</span><br><span class="line">            looping: <span class="keyword">false</span>,</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>####<br>总结：说了这么多，其实Flutter学的是框架，最主要的是学会dart语言。</p>

      
    </div>

    
      

  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="/posts/7a8896fe/" rel="bookmark">鹰眼视频 (三)</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="/posts/47bb6d5/" rel="bookmark">鹰眼视频 (二)</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="/posts/2a2a7e8a/" rel="bookmark">flutter</a></div>
      
    </li>
  
  </ul>


    

    
      
    

    
    
    

    

    
      
    
    

    
      <div>
        




  



<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>修心</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    
    <a href="https://blog.youngzk.com/posts/ab4a2db7/" title="鹰眼视频 (一)">https://blog.youngzk.com/posts/ab4a2db7/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/flutter/" rel="tag"># flutter</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/2a2a7e8a/" rel="next" title="flutter">
                <i class="fa fa-chevron-left"></i> flutter
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/751f2370/" rel="prev" title="D3 数据可视化">
                D3 数据可视化 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>

  </div>


          </div>
          
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  
    <a href="/">
      <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="修心">
      </a>
  
  <p class="site-author-name" itemprop="name">修心</p>
  <div class="site-description motion-element" itemprop="description">修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。</div>
</div>


  <nav class="site-state motion-element">
    
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    

    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">20</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>







  <div class="links-of-author motion-element">
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/1160007652" title="GitHub &rarr; https://github.com/1160007652" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:1160007652@qq.com" title="E-Mail &rarr; mailto:1160007652@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
  </div>



  <div class="cc-license motion-element" itemprop="license">
  
  
    
  
  
  
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>





          
          
        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Flutter-鹰眼视频"><span class="nav-number">1.</span> <span class="nav-text">Flutter - 鹰眼视频</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#目录结构"><span class="nav-number">1.1.</span> <span class="nav-text">目录结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#页面拆封"><span class="nav-number">1.2.</span> <span class="nav-text">页面拆封</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#main-dart-入口文件内容"><span class="nav-number">1.2.1.</span> <span class="nav-text">main.dart 入口文件内容</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#homePage-dart-首页"><span class="nav-number">1.2.2.</span> <span class="nav-text">homePage.dart 首页</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#封装自己的dio"><span class="nav-number">1.3.</span> <span class="nav-text">封装自己的dio</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用懒加载图片特效"><span class="nav-number">1.4.</span> <span class="nav-text">使用懒加载图片特效</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#json自动序列化-model-映射"><span class="nav-number">1.5.</span> <span class="nav-text">json自动序列化 model 映射</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter中如何解析json对象"><span class="nav-number">1.5.1.</span> <span class="nav-text">flutter中如何解析json对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#生成Json解析文件"><span class="nav-number">1.5.2.</span> <span class="nav-text">生成Json解析文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关联实体类文件"><span class="nav-number">1.5.3.</span> <span class="nav-text">关联实体类文件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ListView-组件"><span class="nav-number">1.6.</span> <span class="nav-text">ListView 组件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GestureDetector-手势"><span class="nav-number">1.7.</span> <span class="nav-text">GestureDetector 手势</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#手势事件"><span class="nav-number">1.7.1.</span> <span class="nav-text">手势事件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#onTap-事咧"><span class="nav-number">1.7.2.</span> <span class="nav-text">onTap 事咧</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#路由导航"><span class="nav-number">1.8.</span> <span class="nav-text">路由导航</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#静态路由"><span class="nav-number">1.8.1.</span> <span class="nav-text">静态路由</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#动态路由"><span class="nav-number">1.8.2.</span> <span class="nav-text">动态路由</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#视频播放"><span class="nav-number">1.9.</span> <span class="nav-text">视频播放</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">修心</span>

  

  
</div>

<div>
  修不被别人影响的心，修不被自己控制的心，修不被别人诱惑的心。
</div>









        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    

  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>






  











  
  









  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/fancybox/source/jquery.fancybox.pack.js"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




  <script src="/js/utils.js?v=7.2.0"></script>

  <script src="/js/motion.js?v=7.2.0"></script>



  
  


  <script src="/js/affix.js?v=7.2.0"></script>

  <script src="/js/schemes/pisces.js?v=7.2.0"></script>



  
  <script src="/js/scrollspy.js?v=7.2.0"></script>
<script src="/js/post-details.js?v=7.2.0"></script>



  <script src="/js/next-boot.js?v=7.2.0"></script>

  

  

  


  













  <script src="/js/local-search.js?v=7.2.0"></script>












<script>
// GET RESPONSIVE HEIGHT PASSED FROM IFRAME

window.addEventListener("message", function(e) {
  var data = e.data;
  if ((typeof data === 'string') && (data.indexOf('ciu_embed') > -1)) {
    var featureID = data.split(':')[1];
    var height = data.split(':')[2];
    $(`iframe[data-feature=${featureID}]`).height(parseInt(height) + 30);
  }
}, false);
</script>








  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>
